<template>
  <div>
    <el-row class="business-all">
      <el-col :xs="24" :md="12" :lg="12" :xl="12">
        <h2>成为商家</h2>
        <el-row>
          <el-col :xs="23" :md="12" :lg="12" :xl="12"
            ><input
              type="text"
              required
              placeholder="店铺名字"
              class="business-name"
              v-model="username"
          /></el-col>
        </el-row>
        <el-row>
          <el-col :xs="23" :md="12" :lg="12" :xl="12"
            ><input
              type="text"
              required
              placeholder="店铺描述"
              class="business-name"
              v-model="desc"
          /></el-col>
        </el-row>
        <el-row>
          <el-col :xs="23" :md="12" :lg="12" :xl="12"
            ><input
              type="text"
              required
              class="business-name"
              v-model="fkUserUseridMerchantMerchantid"
              readonly
          /></el-col>
        </el-row>
        <div class="business-text">必须先注册成为用户才能成为商家</div>
        <el-row class="business-button">
          <el-col :xs="23" :md="12" :lg="4" :xl="4"
            ><el-button type="success" @click="regbusiness()"
              >确认注册</el-button
            ></el-col
          >
        </el-row>
      </el-col>
    </el-row>
  </div>
</template>
<script>
export default {
  data() {
    return {
      //店铺描述
      desc: "",
      //用户id
      fkUserUseridMerchantMerchantid: "",
      //店铺名字
      username: "",
    };
  },
  mounted() {
    this.fkUserUseridMerchantMerchantid = this.$store.state.userid;
  },
  watch: {
    "$store.state.username": function () {
      this.fkUserUseridMerchantMerchantid = this.$store.state.userid;
    },
  },
  methods: {
    regbusiness() {
      if (
        this.desc != "" &&
        this.username != "" &&
        this.fkUserUseridMerchantMerchantid != ""
      ) {
        let data = {
          desc: this.desc,
          fkUserUseridMerchantMerchantid: this.fkUserUseridMerchantMerchantid,
          username: this.username,
        };
        this.$axios
          .post("/tMerchant/registemerchant", data
          )
          .then((res) => {
            if (res.data.code == 200) {
              alert("注册成功");
              this.$router.go(-1);
            }
          })
          .catch((err) => {
            console.log(err);
          });
      } else {
        alert("不能为空");
      }
    },
  },
};
</script>
<style scoped>
@import url("../css/business.css");
</style>
